package com.lanou.springbootmybatis.controller;

import com.lanou.springbootmybatis.mapper.UserMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;

@Controller
@RequestMapping("/")
public class HelloController {

	@Resource
	private JdbcTemplate jdbcTemplate;

	@Resource
	private UserMapper userMapper;

	@RequestMapping("hello")
	public ModelAndView hello(String username,ModelAndView modelAndView){
		//User user = jdbcTemplate.queryForObject("select user_name username, pass_word password from t_user where user_name=?",new BeanPropertyRowMapper<User>(User.class),username);
		User user = userMapper.findUserByUsername(username);
		modelAndView.addObject("user",user);
		modelAndView.setViewName("hello");
		return modelAndView;
	}

}
